/* 
* @Author: jimackji
* @Date:   2015-07-31 11:25:26
* @Last Modified time: 2015-07-31 20:26:19
*/


// 定义公共数据
G = {};
G.chart_area_options = {
    title: {text: null},
    yAxis: {title: {text: null},},
    tooltip: {shared: true},
    legend: {enabled: false},
    plotOptions: {
        area: {
            fillColor: {
                linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1},
                stops: [
                    [0, Highcharts.getOptions().colors[0]],
                    [1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')]
                ]
            },
            lineWidth: 1,
            marker: {enabled: false},
            shadow: false,
            states: {hover: {lineWidth: 1}},
            threshold: null,
            enableMouseTracking: true
        }
    }
};

// 加载完成
jQuery(function($){
    // 页面初始化执行
    event_init($);
    // 页面元素绑定
    event_bind($);
});

function event_init($){
    $('.data-container').css({'min-height': $(window).height(), 'padding-top': $('.navbar').height(), 'padding-bottom': $('.footer').height()});
    // $('.chart').css({height: $(window).width()});

    var page = $('body').data('page') || 'index';
    $('body').addClass('page-'+page);
    console.log('current page: '+page);
    if( page=='index' ){
        // 首页
        // 兼容各屏幕浏览器，人的大小
        paint_the_man($);

    } else if ( page=='running' ) {
        // 跑步ing页
        divide_data_container($);
    } else if ( page=='record' ) {
        // 数据页
        divide_data_container($);
        
    }
}

// 请在这里写事件交互
function event_bind($){
    
}


// 切分7、2、1的页面高度
function divide_data_container($){
    var division = {
        'main-area': 0.6923,
        'main-title': 0.1923,
        'sub-title': 0.1154,
    };
    var height_data_container = $('.data-container').height();
    $.each(division, function(k, v){
        var height_current = height_data_container*v;
        $('.data-container .'+k).css({height: height_current, 'line-height': height_current+'px'});
    });
}

// 绘制首页the man
function paint_the_man($){
    var height_man_min = 220;
    var height_man_max = 500;
    var height_man = Math.min(height_man_max, $(window).height()-360);
    height_man = Math.max(height_man, height_man_min);
    $('img.man').css({height: height_man}).removeClass('hide');
    if( height_man==height_man_min ){
        $('img.man').css({bottom: 0});
    }
}

// 测试线条，请前端童鞋自行选择适当的样式
function rend_test($){
    var options = G.chart_area_options;
    options.xAxis = {categories: ['07-21', '07-21', '07-21', '07-21', '07-21', '07-21', '07-21']};
    options.series = [{type:'area', name: '公里数', data: parse_object_float(["12", "13.03", "3.86", "6.08", "8.13", "5.03"])}];
    $('.chart').highcharts(options);
}


function parse_object_float(data_object){
    var data = [];
    $.each(data_object, function(k, v){
        data.push(parseFloat(v));
    });
    return data;
}
